<template>
  <div ref="ter_sec" class="ter-sec" style=" width: 100%;
  height: 100%;"></div>
</template>

<script>
import * as echarts from "echarts";
import { mapState } from "vuex";
export default {
  data() {
    return {
      chartInstance: null,
    };
  },
  computed: {
    ...mapState(["theme"]),
  },
  methods: {
    initChart() {
      // 初始化对象
      this.chartInstance = echarts.init(this.$refs.ter_sec, this.theme);
      let option = {
        color: ["#21ffeb", "#36adff"],
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            label: {
              backgroundColor: "#6a7985",
            },
          },
        },

        grid: {
          left: "3%",
          right: "0%",
          bottom: "10%",
          top: "8%",
          containLabel: true,
        },

        xAxis: [
          {
            type: "category",
            boundaryGap: true,
            data: ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10"],
            axisTick: {
              show: false,
            },
            axisLine: {
              show: false,
            },
            axisLabel: {
              show: true, color: "rgba(255,255,255,0.5)",
  
            },
          },
        ],
        yAxis: [
          {
            type: "value",
            splitLine: {
              lineStyle: {
                color: "#1a1f6d",
                width: 1,
              },
            },
            axisLabel: {
              show: true, color: "rgba(255,255,255,0.5)",
  
            },
          },
        ],

        series: [
          {
            data: [960, 842, 800, 798, 727, 705, 690, 650, 560, 500, 140],
            type: "bar",
            barWidth: 20,
            itemStyle: {
              opacity: 0.6,
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: "#00FFFF",
                },
                {
                  offset: 1,
                  color: "#070C61",
                },
              ]),
            },
          },
        ],
      };
      this.chartInstance.setOption(option);
    },
  },
  mounted() {
    this.initChart();
        // 添加随页面变化而变化
    window.addEventListener('resize', () => {
       this.chartInstance.resize()
    })
  },
      destroyed () {
    window.removeEventListener("resize", () => {
      this.chartInstance.resize();
    });
  },
  watch: {
    theme(newValue, oldValue) {
      this.chartInstance.dispose();
      this.initChart();
    },
  },
};
</script>

<style lang="scss" scoped>
.ter-sec {
  width: 100%;
  height: 100%;
}
</style>